package globalconstants

import (
	"time"
)

const (
	NusServiceUUID         = "0001" //主服务
	NusCharacterUUIDFirst  = "0002" //特征1
	NusCharacterUUIDSecond = "0003" //特征2
	ManufactureConnMarked  = "0104" //发起连接标志

	ManufactureH3CCompany = "ad07" //h3c标记
)

var (
	CtrlLinkedMsgHeader               = 1
	CtrlLinkedMsgHeadWithBoy          = 3
	CtrlLinkedMsgWithMsgAppHeader     = 7
	CtrlAllMsg                        = 15
	EncodeInsertMessageHeaderIndex    = 4
	EncodeInsertMessageAppHeaderIndex = 0
	EncodeInsertMessageTLVIndex       = 4
	EncodeInsertLen                   = 4
	MaxMessageFourLimit               = 0x3f3f3f3f //消息数上限 4 字节
	MaxMessageTwoLimit                = 0x3f3f     //消息数上线 2字节

	GwSocketCachePrefix              = "iotble:gw:server:socket"
	BleDevCacheMessagePrefix         = "iotble:server:dev"     //确认下行消息前缀，后缀终端信息
	BleDevCacheMessageResponsePrefix = "iotble:server:dev:rep" //应答消息前缀
	BleGwDevCacheMessagePrefix       = "iotble:server:gwdev"   //网关下行消息前缀，后缀终端信息
	BleDevCacheConnPrefix            = "iotble:server:dev:conn"

	BleDevInfoCachePrefix  = "iotble:server:infodev" //存储的是当前终端对应最优网关信息，然后就可以通过这个最优网关信息进行数连接
	CacheSeparator         = ":"
	GwIotModuleCachePrefie = "iotble:gw:server:iotstatus"
	BleRedisSNTransfer     = "iotble:sn:transfer"    //依靠mac + id
	GwRedisSNTransfer      = "iotble:gw:sn:transfer" //网关的transfer

	//设备 | 服务 | 特征值
	BleDevSeviceToCharacterPrifix = "iotble:service:character"
	//设备 | 特征 | 服务
	BleDevCharacterToSevicePrifix = "iotble:character:service"

	LimitMessageTime    = time.Hour        //终端消息截至过期时间
	GwMessageLimitTime  = time.Second * 15 //网光消息上行过期时间
	DevMessageLimitTime = time.Second * 30 //终端消息上行过期时间
	TTLDuration         = time.Hour * 7 * 24
	AgingTTLDuration    = time.Second * 30
)

const (
	JudgeGetError = iota //取值错误
	JudgeGetNil          //空
	JudgeGetRes          //取到
)

//暂时封装
var (
	CtrlField       = "0000"
	FragOffset      = "0000"
	ReserveTwo      = "0000"
	ReserveOne      = "0000"
	ReserveOneSmall = "00"
)

//字节对应字符串长度
const (
	BYTE_STR_ONE     int = 1
	BYTE_STR_TWO     int = 2
	BYTE_STR_FOUR    int = 4
	BYTE_STR_EIGHT   int = 8
	BYTE_STR_TWELVE  int = 12
	BYTE_STR_SIXTEEN int = 16
)

//Http Code
const (
	HTTP_CODE_EXCEPTION = -1
	HTTP_CODE_SUCCESS   = 0
	HTTP_CODE_ERROR     = 1
)

//HTTP MESSAGE
const (
	HTTP_MESSAGE_SUCESS           = "success"
	HTTP_MESSAGE_FAILED           = "fail"
	HTTP_MEESAGE_ABSENCE_TERMINAL = "终端对应数据缺失"
	HTTP_MEESAGE_CACHE_EXCEPITON  = "缓存库异常"
	HTTP_ERROR_DATA_ABSENCE       = "部分数据缺失错误"
)

//普通错误
const (
	ERROR_DATA_FORMAT       = "数据格式错误"
	ERROR_DATA_CHANGE       = "数据转化错误"
	ERROR_CACHE_ABSENCE     = "缓存库缺少对应数据"
	ERROR_DATA_GENERATEDOWN = "下行数据生成失败"
	ERROR_DATA_TIMEOUT      = "超时等待"

	ERROR_CACHE_EXCEPTION = "缓存库出现异常"
)

//设备帧校验
const (
	DEV_CORRECT   int = 0
	DEV_ERROR     int = 1
	DEV_EXCEPTION int = -1
)

//服务与特征
const (
	DEV_SERVICE           = "iotble:service"
	DEV_CHARACTER         = "iotble:character"
	DEV_CHARACTER_DEFAULT = 0x3f3f //二字节默认值
)

//MQTT消息队列
const (
	TopicV3GatewayOnline            = "v3/gateway/online"
	TopicV3GatewayTelemetry         = "v3/gateway/telemetry"
	TopicV3GatewayRPC               = "v3/gateway/rpc"
	TopicV3GatewayEventDeviceDelete = "v3/gateway/event/device/delete"
	TopicV3DeviceOnline             = "v3/device/online"
	TopicV3DeviceTelemetry          = "v3/device/telemetry"
	TopicV3DeviceRPC                = "v3/device/rpc"
)

//暂定连接参数
const (
	BLE_CONN_DEV_ADDR_TYPE = 0
	BLE_CONN_SCAN_TYPE     = 1
	BLE_CONN_SCAN_INTERVAL = 72
	BLE_CONN_SCAN_WINDOWS  = 38
	BLE_CONN_SCAN_TIMEOUT  = 500
	BLE_CONN_INTERVAL      = 18
	BLE_CONN_LATENCY       = 0
	BLE_CONN_TIMEOUT       = 400
)

var (
	DeviceURL = "http://localhost:8080/iot/iotware/v2/noauth/device?deviceSN=%s"
)

//链路消息位置
const (
	LOCAL_MESSAGE_MESSAGEHEAD    = "Message Head"
	LOCAL_MESSAGE_MESSAGEAPPHEAD = "Message Apphead"
	LOCAL_MESSAGE_MESSAGEAPPBODY = "Message Appbody"
)

//设备状态
const (
	DEV_STATUS_ONLINE  = 0
	DEV_STATUS_DISABLE = 3
)

//时间戳在redis中的转化
var (
	TimeoutUDPLinked = 30
)
